#!/bin/bash
CHECKS=*,\
-altera-id-dependent-backward-branch,\
-altera-struct-pack-align,\
-altera-unroll-loops,\
-bugprone-exception-escape,\
-bugprone-macro-parentheses,\
-bugprone-reserved-identifier,\
-bugprone-suspicious-include,\
-cert-dcl21-cpp,\
-cert-dcl37-c,\
-cert-dcl51-cpp,\
-cert-dcl58-cpp,\
-cert-err58-cpp,\
-concurrency-mt-unsafe,\
-cppcoreguidelines-avoid-c-arrays,\
-cppcoreguidelines-avoid-magic-numbers,\
-cppcoreguidelines-avoid-non-const-global-variables,\
-cppcoreguidelines-interfaces-global-init,\
-cppcoreguidelines-macro-usage,\
-cppcoreguidelines-non-private-member-variables-in-classes,\
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
-cppcoreguidelines-pro-type-const-cast,\
-cppcoreguidelines-pro-type-member-init,\
-cppcoreguidelines-pro-type-union-access,\
-cppcoreguidelines-pro-type-vararg,\
-cppcoreguidelines-special-member-functions,\
-fuchsia-default-arguments-calls,\
-fuchsia-default-arguments-declarations,\
-fuchsia-multiple-inheritance,\
-fuchsia-overloaded-operator,\
-fuchsia-statically-constructed-objects,\
-fuchsia-trailing-return,\
-google-build-using-namespace,\
-google-readability-braces-around-statements,\
-google-runtime-int,\
-hicpp-avoid-c-arrays,\
-hicpp-braces-around-statements,\
-hicpp-member-init,\
-hicpp-named-parameter,\
-hicpp-no-array-decay,\
-hicpp-signed-bitwise,\
-hicpp-special-member-functions,\
-hicpp-uppercase-literal-suffix,\
-hicpp-vararg,\
-llvm-else-after-return,\
-llvm-header-guard,\
-llvm-include-order,\
-llvm-qualified-auto,\
-llvmlibc-callee-namespace,\
-llvmlibc-implementation-in-namespace,\
-llvmlibc-restrict-system-libc-headers,\
-misc-no-recursion,\
-misc-non-private-member-variables-in-classes,\
-modernize-avoid-bind,\
-modernize-avoid-c-arrays,\
-modernize-concat-nested-namespaces,\
-modernize-return-braced-init-list,\
-modernize-use-trailing-return-type,\
-portability-simd-intrinsics,\
-readability-avoid-const-params-in-decls,\
-readability-braces-around-statements,\
-readability-const-return-type,\
-readability-convert-member-functions-to-static,\
-readability-else-after-return,\
-readability-function-cognitive-complexity,\
-readability-implicit-bool-conversion,\
-readability-magic-numbers,\
-readability-make-member-function-const,\
-readability-named-parameter,\
-readability-qualified-auto,\
-readability-redundant-access-specifiers,\
-readability-uppercase-literal-suffix,\
-readability-use-anyofallof

HEADERS='^('
HEADERS+='(.+/)?\.cxx'
HEADERS+='(.+/)?\.hxx'
HEADERS+='(.+/)?actor\.hpp|'
HEADERS+='(.+/)?algo\.hpp|'
HEADERS+='(.+/)?all\.hpp|'
HEADERS+='(.+/)?concepts\.hpp|'
HEADERS+='(.+/)?coro\.hpp|'
HEADERS+='(.+/)?encoding\.hpp|'
HEADERS+='(.+/)?fs\.hpp|'
HEADERS+='(.+/)?inc\.hpp|'
HEADERS+='(.+/)?json\.hpp|'
HEADERS+='(.+/)?lambda\.hpp|'
HEADERS+='(.+/)?libx\.hpp|'
HEADERS+='(.+/)?macro\.hpp|'
HEADERS+='(.+/)?misc\.hpp|'
HEADERS+='(.+/)?net\.hpp|'
HEADERS+='(.+/)?pc\.hpp|'
HEADERS+='(.+/)?posix\.hpp|'
HEADERS+='(.+/)?print\.hpp|'
HEADERS+='(.+/)?random\.hpp|'
HEADERS+='(.+/)?regex\.hpp|'
HEADERS+='(.+/)?reporter\.hpp|'
HEADERS+='(.+/)?shell\.hpp|'
HEADERS+='(.+/)?stl_concepts\.hpp|'
HEADERS+='(.+/)?string\.hpp|'
HEADERS+='(.+/)?string_types\.hpp|'
HEADERS+='(.+/)?stx\.hpp|'
HEADERS+='(.+/)?time\.hpp|'
HEADERS+=')$'

REPO_ROOT_DIR=/invalid-dir/invalid-dir/invalid-dir
ID=repo_root_dir_tag.511d18f89e52e612aacdfdee949ed23d.txt
PROJECT_DIR=$(pwd)
TMP_DIR=${PROJECT_DIR}

while [[ ! -f ${TMP_DIR}/${ID} ]];
do
	cd ..
	TMP_DIR=$(pwd)

	if [[ ${TMP_DIR} == / ]];
	then
	    echo "Invalid repo directory"
		cd ${PROJECT_DIR}
		exit 1
	fi
done

REPO_ROOT_DIR=${TMP_DIR}

set -x
time clang-tidy -header-filter=${HEADERS} -checks=${CHECKS} \
	-warnings-as-errors=* ${PROJECT_DIR}/main.cpp ${PROJECT_DIR}/stable.cpp \
	-- -std=c++2b -stdlib=libc++ -ferror-limit=10 -m64 -g -pthread \
	-I${PROJECT_DIR} -I${REPO_ROOT_DIR}/stx 